package com.headwind.logistics.system.controller;

import com.headwind.logistics.common.pojo.GoodsType;
import com.headwind.logistics.common.util.LayuiUtil;
import com.headwind.logistics.common.util.RestResult;
import com.headwind.logistics.common.util.ResultGenerator;
import com.headwind.logistics.system.service.intl.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author你爸爸 Date2020/7/18 14:56
 * Version 1.0
 * DESCRIPTION
 */
@Controller
@Transactional
public class GoodsTypeController {
    @Autowired
    private GoodsTypeService goodsTypeService;

    @Resource
    private ResultGenerator resultGenerator;


    //查询
    @RequestMapping("/admin/system/selectGoodsType")
    @ResponseBody
    public LayuiUtil selectGoodsType(Integer page, Integer limit,String goodsName){
        List<GoodsType> list=goodsTypeService.selectGoodsType(page, limit,goodsName);
        return LayuiUtil.data(goodsTypeService.selectGoodsType(null,null,null).size(),list);
    }

    //删除
    @RequestMapping("/admin/system/deleteGoodsType")
    @ResponseBody
    public RestResult deleteGoodsType(Long goodsId){
        int count=goodsTypeService.deleteGoodsType(goodsId);
        if (count>0){
            return  resultGenerator.getSuccessResult("删除成功",count);
        }
        return resultGenerator.getFailResult("删除失败，重新试试？",count);
    }

    //新增
    @RequestMapping("/admin/system/insertGoodsType")
    @ResponseBody
    public RestResult insertGoodsType(String goodsName, String goodsNo){
        GoodsType goodsType=new GoodsType();
        goodsType.setGoodsName(goodsName);
        goodsType.setGoodsNo(goodsNo);
        int count=goodsTypeService.insertGoodsType(goodsType);
        if (count>0){
            return  resultGenerator.getSuccessResult("新增成功",count);
        }
        return resultGenerator.getFailResult("新增失败，重新试试？",count);
    }

    //修改
    @RequestMapping("/admin/system/updateGoodsType")
    @ResponseBody
    public RestResult updateGoodsType(Long goodsId,String goodsName,String goodsNo){
        GoodsType goodsType=new GoodsType();
        goodsType.setGoodsId(goodsId);
        goodsType.setGoodsName(goodsName);
        goodsType.setGoodsNo(goodsNo);
        int count=goodsTypeService.updateGoodsType(goodsType);
        if (count>0){
            return resultGenerator.getSuccessResult("修改成功",count);
        }
        return resultGenerator.getFailResult("修改失败，重新试试？",count);
    }
}